<template>
    <div class='home-container'>
        <aside class="nav-student left-container left-student-container">
            <div class="title">
                <img src="../../src/assets/img/welcome/studentLogo.png" alt="">
            </div>
            <ul class="asideMenu">
                <li v-for="(item,index) in menuList" :key="index">
                    <div class="oneMenu" @click="showToggle(item,index)" @mouseover="mouseMenu(item, index)"
                        @mouseleave="mouseLeave(item, index)" :class="{'activeParent': item.isSubShow}">
                        <img v-bind:src="item.imgUrl" />
                        <span>{{item.name}}</span>
                        <span class="arrow">
                            <!-- <i class="el-icon-arrow-down" v-if="!item.isSubShow"></i>
                            <i class="el-icon-arrow-up" v-else></i> -->
                            <i class="el-icon-arrow-down"
                                :class="{'down': !item.isSubShow, 'up': item.isSubShow, 'icon': true}"></i>
                        </span>
                    </div>
                    <ul v-show="item.isSubShow" class="sub-menu">
                        <li v-for="(subItem, idx) in item.subItems"
                            :class="{'sub-menu-li': true, 'active-li': subItem.active}"
                            @click="showPage(subItem, idx, index, item)" :key="subItem.name">
                            <div class="oneMenuChild">{{subItem.name}}</div>
                        </li>
                    </ul>
                </li>
            </ul>
        </aside>
        <div class='right-container'>
            <router-view></router-view>
        </div>
    </div>
</template>

<script>
export default {
    name: 'Header',
    data() {
        return {
            activeTab: 'Member', // 默认显示会员
            showLightImg: false,
            menuList: [{
                name: '学小思教育',
                imgUrl: require('../../src/assets/img/welcome/navWhiteCat.png'),
                isSubShow: false,
                subItems: [{
                    name: '数学',
                    active: false
                },
                {
                    name: '语文',
                    active: false
                },
                {
                    name: '英语',
                    active: false
                }]
            },
            {
                name: '消防证考试中心',
                imgUrl: require('../../src/assets/img/welcome/navWhiteText.png'),
                isSubShow: false,
                subItems: [{
                    name: '数学',
                    active: false
                },
                {
                    name: '语文',
                    active: false
                },
                {
                    name: '英语',
                    active: false
                }
                ]
            },
            {
                name: '会计专业培训',
                imgUrl: require('../../src/assets/img/welcome/navWhiteBook.png'),
                isSubShow: false,
                subItems: [{
                    name: '数学',
                    active: false
                },
                {
                    name: '语文',
                    active: false
                },
                {
                    name: '英语',
                    active: false
                }
                ]
            }
            ]
        }
    },
    props: {
        openeds: {
            type: Array,
            default: function () {
                return []
            }

        }
    },
    methods: {
        // 点击上面图标
        handleClickIcon(index) {
            if (index === 1) {
                this.activeTab = 'Member'
            }
            if (index === 2) {
                this.activeTab = 'Show'
            }
            if (index === 3) {
                this.activeTab = 'Tv'
            }
            if (index === 4) {
                this.activeTab = 'Text'
            }
        },
        mouseMenu(item, index) {
            if (index === 0) {
                this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navCat.png')
            }
            if (index === 1) {
                this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navText.png')
            }
            if (index === 2) {
                this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navBook.png')
            }
        },
        mouseLeave(item, index) {
            if (!item.isSubShow) {
                if (index === 0) {
                    this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navWhiteCat.png')
                }
                if (index === 1) {
                    this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navWhiteText.png')
                }
                if (index === 2) {
                    this.menuList[index].imgUrl = require('../../src/assets/img/welcome/navWhiteBook.png')
                }
            }
        },
        showToggle: function (item, ind) {
            this.menuList.forEach(i => {
                // 判断如果数据中的menuList[i]的show属性不等于当前数据的isSubShow属性那么menuList[i]等于false
                if (i.isSubShow !== this.menuList[ind].isSubShow) {
                    i.isSubShow = false
                }
            })
            item.isSubShow = !item.isSubShow
            this.menuList[0].imgUrl = require('../../src/assets/img/welcome/navWhiteCat.png')
            this.menuList[1].imgUrl = require('../../src/assets/img/welcome/navWhiteText.png')
            this.menuList[2].imgUrl = require('../../src/assets/img/welcome/navWhiteBook.png')
            if (ind === 0) {
                this.menuList[ind].imgUrl = require('../../src/assets/img/welcome/navCat.png')
            }
            if (ind === 1) {
                this.menuList[ind].imgUrl = require('../../src/assets/img/welcome/navText.png')
            }
            if (ind === 2) {
                this.menuList[ind].imgUrl = require('../../src/assets/img/welcome/navBook.png')
            }
        },
        showPage(item, idx, index, parentItem) {
            this.$router.push({
                path: '/studentMange/schoolCourses', //跳转的路径
                query: {
                    parentName: parentItem.name
                }
            })
            // eslint-disable-next-line no-return-assign
            this.menuList[index].subItems.map(it => it.active = false)
            this.menuList.map((item, index) => {
                // eslint-disable-next-line no-undef,no-return-assign
                it.subItems.map(item => item.active = false)
            })
            this.menuList[index].subItems[idx].active = true
        }
    }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
    @import url('../../src/assets/less/Mixins.less');
    @import url('../../src/assets/less/common.less');

    .left-container {
        width: 224px;
        /*float: left;*/
        box-shadow: 0px 0px 12px 0px rgba(113, 113, 113, 0.5);

        .el-menu {
            width: 224px;
        }

        .title {
            height: 80px;

            img {
                width: 224px;
                height: 80px;
            }

            /*background: #55A8FD;*/
            /*font-size:26px;*/
            /*line-height: 80px;*/
            /*color: #ffffff;*/
        }

        .circle {
            height: 4px;
            width: 4px;
            background: #55A8FD;
            border-radius: 2px;
            position: relative;
            top: 30px;
            left: 60px;
        }

        .icon-list {
            img {
                width: 16px;
                height: 16px;
            }

            height: 36px;
            /*background: #22345E;*/
            background: rgb(56, 73, 114);
            .flex(row, space-between, center, nowrap);

            .deepColor {
                background: #22345E;
            }

            span {
                height: 100%;
                width: 25%;
                cursor: pointer;
                text-align: center;

                img {
                    margin-top: 8px;
                }

            }
        }

        .nav-title {
            &::before {
                height: 4px;
                width: 4px;
                content: "";
                background: #53CC90;
                border-radius: 2px;
                display: inline-block;
                position: relative;
                left: -10px;
                top: -2px;
                // position: absolute;
                // left: 0px;
                // top: 27%;

            }
        }

        .active-line {
            height: 45px;
            line-height: 45px;
            background: #22345E;
            color: #FFFFFF;
            text-align: left;
            font-size: 14px;
            padding-left: 20px;
            position: relative;

            &::before {
                height: 32%;
                width: 2px;
                content: "";
                background: #55A8FD;
                position: absolute;
                left: 0px;
                top: 35%;
                display: inline-block;
            }
        }

        .el-menu {
            a {
                color: #FFFFFF;
                text-decoration: none;
            }
        }
    }

    .left-student-container {
        background-color: #4E546C !important
    }

    .nav-student {
        img {
            width: 20px;
            height: 20px;
        }

        ul {
            background-color: #4E546C !important;
            /*list-style-type:none;*/
            padding: 0px;
            margin-top: 0px;

            li {
                cursor: pointer
            }
        }

        .oneMenu {
            height: 56px;
            line-height: 56px;
            font-size: 14px;
            font-family: PingFang-SC-Regular !important;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
            cursor: pointer;
            position: relative;

            &:hover {
                color: rgba(83, 204, 144, 1);
                background: rgba(255, 255, 255, 0.1);
            }

            .arrow {
                position: absolute;
                right: 30px;

                .down {
                    -ms-transform: rotate(0deg);
                    /* IE 9 */
                    -moz-transform: rotate(0deg);
                    /* Firefox */
                    -webkit-transform: rotate(0deg);
                    /* Safari 和 Chrome */
                    -o-transform: rotate(0deg);
                    /* Opera */
                }

                .up {
                    -ms-transform: rotate(180deg);
                    /* IE 9 */
                    -moz-transform: rotate(180deg);
                    /* Firefox */
                    -webkit-transform: rotate(180deg);
                    /* Safari 和 Chrome */
                    -o-transform: rotate(180deg);
                    /* Opera */
                }

                .icon {
                    -ms-transition: transform .3s;
                    /* IE 9 */
                    -moz-transition: transform .3s;
                    /* Firefox */
                    -webkit-transition: transform .3s;
                    /* Safari 和 Chrome */
                    -o-transition: transform .3s;
                    /* Opera */
                }
            }

            border-bottom: 1px solid rgba(255, 255, 255, 0.1);

            img {
                width: 20px;
                height: 20px;
                margin: 17px 8px 15px 35px;
                vertical-align: top;
            }
        }

        .activeParent {
            color: rgba(83, 204, 144, 1);
            background: rgba(255, 255, 255, 0.1);
        }

        .sub-menu {
            .sub-menu-li {
                font-size: 14px;
                font-family: PingFang-SC-Regular !important;
                font-weight: 400;
                color: rgba(255, 255, 255, 1);
                height: 40px;
                line-height: 34px;
                padding-left: 90px;
                list-style-type: none;
                cursor: pointer;

                &::before {
                    height: 4px;
                    width: 4px;
                    content: "";
                    background: #fff;
                    border-radius: 2px;
                    position: relative;
                    left: -20px;
                    top: 20px;
                    display: block;

                }

                &:hover {
                    color: rgba(83, 204, 144, 1);
                    background: rgba(255, 255, 255, 0.1);

                    &::before {
                        background: rgba(83, 204, 144, 1);
                    }
                }

            }

            .active-li {
                background: rgba(255, 255, 255, 0.1) !important;
                color: #53CC90 !important;

                &::before {
                    background: rgba(83, 204, 144, 1);
                }
            }
        }

        /*.oneMenuChild {*/
        /*    padding: 0 20px 0 60px;*/
        /*    height: 40px;*/
        /*    line-height: 40px;*/
        /*    // font-size: 18px;*/
        /*}*/
    }

    .nav-title {
        &::before {
            height: 4px;
            width: 4px;
            content: "";
            background: #55A8FD;
            border-radius: 2px;
            display: inline-block;
            position: relative;
            left: -10px;
            top: -2px;
            // position: absolute;
            // left: 0px;
            // top: 27%;

        }
    }

    .right-container {
        >div {
            height: 100%;
        }
    }

</style>
<style lang='less'>
    .nav-student {
        .el-submenu__title {
            line-height: 56px !important;
            height: 56px !important;
            padding-left: 34px !important;

            &:hover {
                background: rgba(255, 255, 255, 0.1) !important;
                color: #53CC90 !important;
            }
        }

        .el-menu-item-group {
            >div {
                display: none !important;
            }

            ul li {
                padding: 0px !important;

                a {
                    width: 100%;
                    height: 100%;
                    display: block;
                    padding-left: 65px !important;

                }

            }

            .el-menu-item {
                line-height: 40px !important;
                height: 40px !important;

                &:hover {
                    background: rgba(255, 255, 255, 0.1) !important;
                    color: #53CC90 !important;
                }

                a:hover {
                    color: #53CC90 !important;
                }
            }

            .router-link-exact-active {
                background: rgba(255, 255, 255, 0.1) !important;
                color: #53CC90 !important;
                width: 160px;
            }

        }

        .el-submenu__icon-arrow {
            &::before {
                /*position: relative;*/
                /*left: 10px;*/
                color: #fff;
            }
        }

        .el-menu-item:focus,
        .el-menu-item:hover {
            background: rgba(78, 84, 108, 0.1) !important;
            color: #fff;
        }
    }

</style>
